package com.yanqu.road.server.cmd.cross.player;

import com.yanqu.road.entity.player.UserInfo;
import com.yanqu.road.utils.YanQuMessageUtils;
import com.yanqu.road.pb.player.PlayerProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.player.UserMgr;
import com.yanqu.road.server.manger.player.GamePlayerMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.S_CROSS_TO_WATCH_PLAYER_PATRONS, desc = "跨服拜访玩家")
public class CrossWatchPlayerPatronsCmd extends AbstractCommand {

	private long userId;

	private long serverId;

	private int patronsId;

	private long watchUserId;

	private long watchServerId;

	//门客的信息搞成字符串给客户端，和排行榜一致方便客户端解析
	private String resStrParam;

	@Override
	public boolean parseData(YanQuMessage packet) throws Exception {
		PlayerProto.CrossWatchPlayerPatronsReqMsg reqMsg = PlayerProto.CrossWatchPlayerPatronsReqMsg.parseFrom(packet.getBytes());
		userId = reqMsg.getUserId();
		serverId = reqMsg.getServerId();
		patronsId = reqMsg.getPatronsId();
		watchUserId = reqMsg.getWatchUserId();
		watchServerId = reqMsg.getWatchServerId();
		return true;
	}

	@Override
	public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
		resStrParam = UserMgr.watchPlayerPatron(watchUserId,patronsId);
	}

	@Override
	public void sendData(GamePlayer player) {
		PlayerProto.CrossWatchPlayerPatronsRespMsg.Builder respMsg = PlayerProto.CrossWatchPlayerPatronsRespMsg.newBuilder();
		respMsg.setUserId(userId);
		respMsg.setServerId(serverId);
		respMsg.setWatchUserId(watchUserId);
		respMsg.setWatchServerId(watchServerId);
		UserInfo userInfo = UserMgr.getUserInfo(watchUserId);
		respMsg.setNickName(userInfo.getNickName());
		respMsg.setPatronsId(patronsId);
		respMsg.setRespData(resStrParam);
		YanQuMessage pbMsg = YanQuMessageUtils.buildMessage(Protocol.C_CROSS_WATCH_PLAYER_PATRONS_RESP, respMsg);
		GamePlayerMgr.sendPacket(0, pbMsg);
	}
}
